package com.hbnu.service.impl;

import com.hbnu.domain.LoginTourist;
import com.hbnu.tourist.domain.Tourist;
import com.hbnu.tourist.mapper.TouristMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class TouristDetailServiceImpl implements UserDetailsService {
    @Autowired
    private TouristMapper touristMapper;
    @Override
    public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException {
        log.info("邮箱号：{}",email);
        Tourist tourist = touristMapper.selectTouristByEmail(email);
        if (tourist == null) {
            log.info("用户名不存在");
            throw new UsernameNotFoundException("用户名错误");
        }
        System.out.println(tourist);
        System.out.println(new LoginTourist(tourist));
        return new LoginTourist(tourist);
    }
}
